// 引入框架并创建服务器
const express = require('express');
const app = express();
const config = require('./config')
//设置跨域请求
app.all('*', function (req, res, next) {
    //设置请求头
    //允许所有来源访问
    res.header('Access-Control-Allow-Origin', '*')
    //用于判断request来自ajax还是传统请求
    // res.header('Access-Control-Allow-Headers', 'X-Requested-With')
    res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
    //允许访问的方式
    res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS')
    //修改程序信息与版本
    res.header('X-Powered-By', ' 3.2.1')
    //内容类型：如果是post请求必须指定这个属性
    res.header('Content-Type', 'application/json;charset=utf-8')
    next()
})

/************ node做图片服务器 */
//图片加载,存储在public/images下的所有图片
app.use('static', express.static('./public'));
app.get('/public/images/*', function (req, res) {
    res.sendFile(__dirname + "/" + req.url);
})

const course = require('./routes/wpw/router.js');
app.use('/api', course);

// 引入配置文件
const {
    server
} = require('./config');

// 引入bodyParser
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({
    extended: false
}));

//登录路由
// app.use('/api/v1',require('./routes/login.js'));
// app.use('/api/v1', require('./routes/login.js'));node

/************ 在这里引入路由并注册 */
// app.use('/api/v1', require('./routes/students'));

// 引入azn路由
app.use('/api/v1', require('./routes/azn/recruit'));

// 引入dpx路由
app.use('/api/v1', require('./routes/dpx/info'));
app.use('/api/v1', require('./routes/dpx/ebookLabel'));


// wpw的路由
app.use('/api/v1', require('./routes/wpw/router.js'));
app.use('/api/v1', require('./routes/cty/text.js'));

app.use('/api/v1', require('./routes/gc/allbooks'))
app.use('/api/v1', require('./routes/gc/logistics'))
//引入dbw的路由
app.use('/api/v1', require('./routes/dbw/video'));
app.use('/api/v1', require('./routes/dbw/textbook'));

// wyq路由
app.use('/api/v1', require('./routes/wyq/index'));




// 启动服务器
app.listen(config.server.port, config.server.ip, () => console.log(`http://127.0.0.1:${config.server.port}`))